package cwb.dto;

/**
 * @author Ezio.Auditore
 */
public class ResultData {
    /**
     * 状态码，0表示成功，1表示处理中，-1表示失败
     */
    private Integer code;
    /**
     * 业务数据
     */
    private Object data;
    /**
     * 信息描述
     */
    private String msg;

    public ResultData() {

    }

    public ResultData(Integer code, Object data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    /**
     * 成功，不返回数据
     * @return
     */
    public static ResultData buildSucess() {
        return new ResultData(0, null, null);
    }

    /**
     * 成功，返回数据
     * @param data
     * @return
     */
    public static ResultData buildSucess(Object data) {
        return new ResultData(0, data, "success");
    }

    /**
     * 失败，返回错误信息
     * @param msg
     * @return
     */
    public static ResultData buildError(String msg) {
        return new ResultData(-1, null, msg);
    }

    /**
     * 失败，返回自定义状态码以及错误信息
     * @param code
     * @param msg
     * @return
     */
    public static ResultData buildError(Integer code, String msg) {
        return new ResultData(code, null, msg);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "ResultData{" +
                "code=" + code +
                ", data=" + data +
                ", msg='" + msg + '\'' +
                '}';
    }
}

